package vip.liux.backend.adapter.web.generator;

import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import vip.liux.application.dots.ListResultDto;
import vip.liux.application.dots.PagedResultDto;
import vip.liux.application.dots.PagedResultRequestDto;
import vip.liux.backend.application.service.gen.GenDataSourceService;
import vip.liux.backend.domain.models.gen.GenDataSource;

@RestController
@RequestMapping("/api/generator/database")
public class DataBaseController {

    private final GenDataSourceService databaseService;

    public DataBaseController(GenDataSourceService databaseService) {
        this.databaseService = databaseService;
    }

    @GetMapping
    public PagedResultDto<GenDataSource> pageList(PagedResultRequestDto input) {
        return databaseService.pageList(input);
    }

    @GetMapping("/{id}")
    public GenDataSource detail(@PathVariable Long id) {
        return databaseService.detail(id);
    }

    @PostMapping
    public GenDataSource save(@Valid @RequestBody GenDataSource input) {
        return databaseService.save(input);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id) {
        databaseService.delete(id);
    }

    @GetMapping("/list")
    public ListResultDto<GenDataSource> list() {
        return databaseService.list();
    }

    @PutMapping("/{id}")
    public GenDataSource update(@PathVariable Long id, @Valid @RequestBody GenDataSource input) {
        return databaseService.update(id, input);
    }
}
